package nl.wubinator.aeve.xmlconverters.limited.parsers;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import nl.wubinator.aeve.models.limited.skillqueue.QueuedSkill;

import org.xml.sax.Attributes;

import android.util.Log;

public class QueuedSkillParser {
	public static QueuedSkill parseAttributes(Attributes atts) {
		QueuedSkill skill = new QueuedSkill();

		try {
			DateFormat dateFormatter = new SimpleDateFormat(
					"yyyy/dd/mm HH:mm:ss");
			// The character consists of the following attributes:
			// - queuePosition
			// - typeID
			// - level
			// - startSP
			// - endSP
			// - startTime
			// - endTime
			skill.setQueuePosition(Integer.parseInt(atts
					.getValue("queuePosition")));
			skill.setTypeID(Integer.parseInt(atts.getValue("typeID")));
			skill.setLevel(Integer.parseInt(atts.getValue("level")));
			skill.setStartSP(Integer.parseInt(atts.getValue("startSP")));
			skill.setEndSP(Integer.parseInt(atts.getValue("endSP")));
			skill.setStartTime(dateFormatter.parse(atts.getValue("startTime")));
			skill.setEndTime(dateFormatter.parse(atts.getValue("endTime")));

		} catch (ParseException e) {
			Log.e("Parsing date failed:", e.getMessage());
		}

		return skill;
	}
}
